package com.clg.protobuf.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * gzip filter
 * Created by chenlong on 2017/6/2.
 */
public class GzipFilter implements Filter {

	private Logger logger = LoggerFactory.getLogger(GzipFilter.class);

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		logger.info("初始化 gzip filter");
	}

	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
		logger.info("gzip 解压缩");
		filterChain.doFilter(new GzipRequestWrapper((HttpServletRequest) servletRequest), servletResponse);
	}

	@Override
	public void destroy() {
		logger.info("销毁 gzip filter");
	}
}
